package map01;

import java.util.HashMap;

/**
 * boolean isEmpty()
 *            如果map中没有键值对则返回true,如果map中有键值对则返回false
 * boolean containsKey(Object key)
 *           判断指定的key在map中是否存在,如果存在返回true,否则返回false
 *   V remove(Object key)
 *           根据key移除map中的键值对,返回该key对应的value
 *           如果该key对应的value不存在,那么返回null
 */
public class HashMapDemo02 {
    public static void main(String[] args) {
        //method01();
        //method02();
        HashMap<Integer, String> hm = new HashMap<>();
        hm.put(123, "张三");
        hm.put(456, "李四");
        hm.put(78, "王五");

        String str = hm.remove(78);
        System.out.println(str);
        System.out.println(hm);

        System.out.println(hm.remove(13));//null
        System.out.println(hm);
    }

    private static void method02() {
        HashMap<Integer, String> hm = new HashMap<>();
        hm.put(123, "张三");
        hm.put(456, "李四");
        hm.put(78, "王五");

        System.out.println(hm.containsKey(456));//true
        System.out.println(hm.containsKey(13));//false
    }

    private static void method01() {
        HashMap<Integer, String> hm = new HashMap<>();
        hm.put(123, "张三");
        hm.put(456, "李四");
        hm.put(78, "王五");
        System.out.println(hm.isEmpty());//false

        hm.clear();
        System.out.println(hm.isEmpty());//true
    }
}
